#include "mainwindow.h"

#include <QApplication>
#include <QDebug>
#include <string>
#include <vector>
#include <QVector>
#include "Shape.pb.h"
#include "SerializeManager.h"

using std::string;
using std::vector;

void write(QString path)
{
    SerializeManager* manager = SerializeManager::instance();
    Shape r = manager->getARect(1, 1, 1, 2);
    Shape c = manager->getACircle(2, 3, 4, 5);

    QVector<Shape> vec;
    vec.append(r);
    vec.append(c);

    manager->saveToFile(vec, path);

}

void read(QString path)
{

    Shape sp;
    sp.ParseFromString(data);

    if (sp.type() == Shape_ShapeType_RECT)
    {
        // TODO ...
    }
    else if (sp.type() == Shape_ShapeType_CIRCLE)
    {
        // TODO ...
    }
    else if (sp.type() == Shape_ShapeType_BACKOUT)
    {
        // 撤回 TODO ...
    }
    else if (sp.type() == Shape_ShapeType_CIRCLE)
    {
        // 清空 TODO ...
    }

    SerializeManager* manager = SerializeManager::instance();
    QVector<Shape> vec;
    manager->parseFromFile(vec, path);

    for (int i = 0; i < vec.size(); i ++)
    {
        qDebug() << vec[i].x() << " " << vec[i].w() << " " << vec[i].type();
    }
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    write("data.dat");
    read("data.dat");

    return a.exec();
}
